<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<c:set var="serviceurl" value="${ctx}/pro/asset" />
<c:set var="serviceurl1" value="${ctx}/pro/property" />
<html>
<head>
</head>
<body>
	<div class="container-fluid rap-select-container" id="rap-container-list">
		<div class = "rap-select-toolbar">
			<button id="ok"><i class="glyphicon glyphicon-ok"></i> 恢复</button>
			<button id="close" ><i class=""></i> 关闭</button>
		</div>
		<form id="rap-form-select">
		<input type='hidden' name='search_EQ_valid' value='0'>
		<div class="form-inline rap-searchbar-compact">
			<div class="form-group">
				<label for="search_LIKE_theName">资产名称</label> 
				<input type="text" class="form-control" id="search_LIKE_theName"
					name="search_LIKE_theName" autocomplete="on">
			</div>
			<label>所属物业：</label>
			<div class="input-group">
				<input type='hidden' name='search_IN_groupOne' class="stwy_search_groupOne">
				<input type='hidden' name='search_IN_groupTwo' class="stwy_search_groupTwo">
				
				<input name="search_EQ_property.uuid" type="hidden"  id="propertyId"> 
				<input type="text" name="propertyName" id="propertyName" >
				<span class="input-group-addon rap-btn-ref" id="rap-btn-ref-property">
				<i class="fa fa-search"></i>
				</span>
			</div>
		</div>
		</form>
		<div class="row-fluid">
			<table id="tableList" class="table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<th ><input type="checkbox" /> <span class="lbl"></span></th>
						<th>资产名称</th>
						<th>所属物业</th>
						<th>资产面积</th>
						<th>区域</th>
						<th>用途</th>
						<th>状态</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
				</tbody>
			</table>
		</div>
	</div>
	<script type="text/javascript">
		var _isServerPage = true;
		//变量定义
		var _tableList, _queryData, _detailRecord, _detailRecordIdx, _validator;
		var _isMulti="${param.isMulti}";//是否多选
		var _tableCols = 	[{
			data : "uuid",
			orderable : false,
			className : "center",
			width : "30",
			render : RapDataTableUtils.renderCheckCol
		},
		{
			data : 'theName',
			width : "120",
			render : function(data, type, full) {
				return RapDataTableUtils.renderStrByLength(data,24);
			},
			orderable : false
		},
		{
			data : null,
			width : "120",
			render : function(data, type, full) {
				var content = data.property==null?"":data.property.theName;
				return RapDataTableUtils.renderStrByLength(content,24);
			},
			orderable : false
		},
		{
			data : 'area',
			width : "120",
			className :"rap-td-number",
			render:milliFormat,
			orderable : false
		},
		{
			data : 'region',
			width : "120",
			orderable : false,
			render : function(data, type, full) {
				return RapDataUtils.getEnumName("stwy_region", data);
			}
		},
		{
			data : 'usefor',
			width : "120",
			orderable : false,
			render : function(data, type, full) {
				return RapDataUtils.getEnumName("stwy_usefor", data);
			}
		},
		{
			data : 'assetState',
			width : "120",
			render : function(data, type, full) {
				return RapDataUtils.getEnumName("stwy_assetStatus", data);
			},
			orderable : false
		},
		{
			data : "uuid",
			className : "center",
			orderable : false,
			render : function(data, type, full){
				return "<div class='rap-btn-actiongroup'>" 
				+ "<button id='selectBtn' class='btn btn-xs btn-info' data-rel='tooltip' title='恢复'>恢复</button>"
				+ "</div>";
			},
			width : "80"
		}]
	;
		function appendUrlParams(){
			var _params = "${param}";
			if(_params==null||_params.length==0){
				return false;
			}
			if(_queryData==null){
				_queryData=new Array();
			}
			_params = _params.replace("{","");
			_params = _params.replace("}","");
			var paramObj = _params.split(",");
			
			for(var i=0;i<paramObj.length;i++){
				var nameAndValue = paramObj[i].split("=");
				var name = $.trim(nameAndValue[0]);
				var value = $.trim(nameAndValue[1]);
				if($("#rap-form-select [name='"+name+"']").length>0){
					$("#rap-form-select [name='"+name+"']").val(value);
				}else{
					$("#rap-form-select").append("<input type='hidden' name='"+name+"' value='"+value+"'>");
				}
			} 
		}				
		//加载表格数据
		function loadList() {
			$.ajax({
				url : '${serviceurl}/query',
				data : _queryData,
				dataType : 'json',
				success : function(data) {
					_tableList.clear();
					_tableList.rows.add(data.records);
					_tableList.draw();
				}
			});
		}
		
		function callbackProperty(data){
			$("#propertyId").val(data.uuid);
			$("#propertyName").val(data.theName);
			if(!_queryData){
				_queryData=new Array();
			}
			_queryData.push({name:"search_EQ_property.uuid",value:data.uuid});
			if(_isServerPage)
				_tableList.draw();	//服务器分页
			else
				loadList();
		}
		function serverPage(){
			_tableList = $('#tableList').DataTable({
				"columns" : _tableCols,
				"createdRow" : setActions,
				"order": [] ,
				"processing" : true,
				"serverSide": true,
				"searching": false,
				"pagingType": "full_numbers",
				"paging": true,
			     "ajax" : {
					"url" : "${serviceurl}/query",
					"type": 'POST',
					"data" : function(d) {
						 d.orderby = getOrderbyParam(d);
						if (_queryData == null)
							return;
						$.each(_queryData, function(index) {
							if (this['value'] == null || this['value'] == "")
								return;
							d[this['name']] = this['value'];
						});
					},
			  	    "dataSrc" : function(json) {
		             return json.records==null?[]:json.records;
		            }
				} 
			});
		}
		function getOrderbyParam(d){
			var orderby = d.order[0];
			if(orderby!=null&&null!=_tableCols){
				var dir=orderby.dir;
				var orderName = _tableCols[orderby.column].data;
				return orderName+"@"+dir;
			}
			return "";
		}
		function initPage(){
			
		}
		function setActions(nRow, aData, iDataIndex){
			
			$("#selectBtn",nRow).click(function() {
				reuse([aData.uuid]);
			});
		}
		function onRefresh() {
			if(_isServerPage)
				_tableList.draw();	//服务器分页
			else
				loadList();		//非服务器分页
		}
		function reuse(pks){
			if(pks==null||pks.length==0){
				alert('请选择要恢复的记录');
				return;
			}
			$.ajax({
				url : '${serviceurl}/reuse',
				data : {"pks":pks.toString()},
				dataType : 'json',
				success : function(data) {
					alert("恢复成功,在首页刷新即可看到恢复的记录");
					onRefresh();
				}
			});
		}
		function reuses(){
			var pks = RapDataTableUtils.getSelectPks();
			reuse(pks);
		}
		$(document).ready(function() {
			initPage();
			appendUrlParams();
			_queryData = $("#rap-form-select").serializeArray();
			if(_isServerPage){
				//服务器分页
				serverPage();	
			}else{
				//非服务器分页
				_tableList = $('#rap-table-list').DataTable({
					"columns" : _tableCols,
					"createdRow" : RapDataTableUtils.setActions,
					"order": [] 
				});
				loadList();		
			}
			RapDataTableUtils.setCheckCol(_tableList);
			
			$("#rap-btn-ref-property").colorbox({
				iframe : true,
				opacity	: 0.8,
				transition : 'none',
				speed : 200,
				href : "${ctx}/pro/property/select?search_EQ_status=1&callback=callbackProperty",
				width : '100%',
				height : '100%',
				close : '×',
				fixed : true
			});
			$('#propertyName').bind('focus', function(){
				$("#rap-btn-ref-property").click();
			});
			$("#ok").bind("click",function(){
				reuses();
			});
			$("#close").bind("click",function(){
				window.parent.$.colorbox.close();
			});
		});
	</script>
</body>
</html>
